#pragma strict
////////////////////////////////////////////////////////////////////////////////////
///找到.场景内所有的摄影机.
////////////////////////////////////////////////////////////////////////////////////
static var instance:CameraManager;
var cameras:Camera[];
var fadeTime:float = 3; //摄影机fade时间.

var OnFadeOut:String = "OnFadeOut";

function Awake(){
	instance = this;
	GatherCameras();
}

function OnLevelWasLoaded(level:int) {
	GatherCameras();
	Debug.Log("收集摄影机:"+level);
}

function GatherCameras(){
	cameras = FindObjectsOfType(Camera) as Camera[];
}

function SendMessageAllCamera(msg:String,value:Object){
	Debug.Log("通知所有摄影机:msg"+msg);
	if(cameras){
		for(var c:Camera in cameras){
			if(c)
				c.gameObject.SendMessage(msg,value);
		}
	}
}

function WaitForCameraFade():IEnumerator{
	SendMessageAllCamera("OnFadeOut",null);
	//等待摄影机fadeout完毕.
	yield WaitForSeconds(fadeTime);
}